package org.example.task.service.impl;

import lombok.RequiredArgsConstructor;
import org.example.task.converter.DeptConverterMapper;
import org.example.task.model.dto.department.CreateDeptDTO;
import org.example.task.model.dto.department.UpdateDeptDTO;
import org.example.task.model.po.Department;
import org.example.task.mapper.DepartmentMapper;
import org.example.task.service.IDepartmentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author author
 * @since 2025-05-26
 */
@Service
@RequiredArgsConstructor
public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Department> implements IDepartmentService {
    private final DeptConverterMapper deptConverterMapper;

    @Override
    public boolean addDept(CreateDeptDTO createDeptDTO) {
        Department dept = deptConverterMapper.createDeptToDept(createDeptDTO);
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        return save(dept);
    }

    @Override
    public boolean modifyDept(UpdateDeptDTO updateDeptDTO) {
        Department department = deptConverterMapper.updateDeptToDept(updateDeptDTO);
        department.setUpdateTime(LocalDateTime.now());
        return updateById(department);
    }
}
